package com.big.spike.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.big.common.result.Result;
import com.big.model.model.merchandise.MerchandiseSpike;
import com.big.spike.service.MerchandiseSpikeService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;


@RestController
@RequestMapping("/api/spike")
public class MerchandiseSpikeController {


    @Autowired
    MerchandiseSpikeService merchandiseSpikeService;

    @PostMapping("/merchan/infos/{page}/{limit}")
    @ApiModelProperty(value = "秒杀商品列表")
    public Result spikeMerchant(@PathVariable Long page ,@PathVariable Long limit) {
        Page<MerchandiseSpike> pages = new Page<>(page, limit);
        IPage<MerchandiseSpike> merchandiseSpikeIPage = merchandiseSpikeService.MerchandiseSpike(pages);
        return Result.ok(merchandiseSpikeIPage);
    }

    @PostMapping("/merchan/spike/{spikeId}")
    @ApiModelProperty(value = "添加秒杀商品缓存")
    public Result SaveSpikeRedis(@PathVariable Long spikeId) throws ParseException {
        merchandiseSpikeService.spikesRedis(spikeId);
        return Result.ok();
    }

    @GetMapping("/merchan/remind/{uId}/{mId}")
    @ApiModelProperty(value = "秒杀提醒我")
    public Result RemindMe(@PathVariable String uId, @PathVariable String mId) throws ParseException {

        boolean b = merchandiseSpikeService.MerchRemindMe(uId, mId);
        return Result.ok(b==true ? true : false );
    }
}
